package com.boco.modules.fdoc.web.pmdochospital;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.boco.common.persistence.Page;
import com.boco.common.web.ServletController;
import com.boco.modules.fdoc.model.PmDoctorHospitalEntity;
import com.boco.modules.fdoc.service.PmDoctorHospitalService;

@Controller
@RequestMapping(value = "/pmdh")
public class PmDocHosCtr extends ServletController {
	@Resource
	PmDoctorHospitalService pmDoctorHospitalService;

	@RequestMapping(value = "/goPmDocHosPage")
	public ModelAndView goPmDocHosPage() {
		return new ModelAndView("/pmdh/dochospitalmgmt");
	}

	/**
	 * pmdh/qryPmDocHosLst qryPmDocHosLst:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author ken
	 * @param request
	 * @param response
	 * @param entity
	 * @return
	 */
	@RequestMapping(value = "/qryPmDocHosLst")
	public ModelAndView qryPmDocHosLst(HttpServletRequest request, HttpServletResponse response,
			PmDoctorHospitalEntity entity) {
		Page<PmDoctorHospitalEntity> page = new Page<PmDoctorHospitalEntity>(request, response);

		try {
			page = pmDoctorHospitalService.getPmDocHosLst(page, entity);
			List<PmDoctorHospitalEntity> pmList = page.getList();

			int pmLstNum = pmList.size();
			/** 完成率 */
			double a = 0.00;
			/** 及时率 */
			double b = 0.00;
			/** 缺项率 */
			double c = 0.00;
			for (PmDoctorHospitalEntity pmEntity : pmList) {

				a = a + pmEntity.getRate();

				b = b + (double) pmEntity.getIsTime() / pmEntity.getTotal();

				c = c + (double) (pmEntity.getTotal() - pmEntity.getServicecount()) / pmEntity.getTotal();
			}
			a = a / pmLstNum;
			a=Double.parseDouble(String.format("%.2f",a)); 
			b = b / pmLstNum*100;
			b=Double.parseDouble(String.format("%.2f",b)); 
			c = c / pmLstNum*100;
			c=Double.parseDouble(String.format("%.2f",c)) ; 
			System.out.println("a是什么" + a + "b是什么" + b + "c是什么" + c);
			request.setAttribute("a", a);
			request.setAttribute("b", b);
			request.setAttribute("c", c);
			return new ModelAndView("/pmdh/dochospitalmgmt").addObject("pageList", page).addObject("page", page)
					.addObject("option", entity);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("获取统计信息失败", e);
			// 返回界面，提示错误信息
			return new ModelAndView("/pmdh/dochospitalmgmt").addObject("errorInfo", "获取统计信息失败");
		}
	}

	@RequestMapping(value = "/qryPmDocHosIsTimeLst")
	public ModelAndView qryPmDocHosIsTimeLst(HttpServletRequest request, HttpServletResponse response,
			PmDoctorHospitalEntity entity) {
		Page<PmDoctorHospitalEntity> page = new Page<PmDoctorHospitalEntity>(request, response);

		try {
			page = pmDoctorHospitalService.getPmDocHosLst(page, entity);
			return new ModelAndView("/pmdh/dochospitalmgmt").addObject("pageList", page).addObject("page", page)
					.addObject("option", entity);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("获取统计信息失败", e);
			// 返回界面，提示错误信息
			return new ModelAndView("/pmdh/dochospitalmgmt").addObject("errorInfo", "获取统计信息失败");
		}
	}

}
